package com.powernode.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class FeignTokenInterceptor implements RequestInterceptor {
    @Autowired
    private HttpServletRequest httpServletRequest;
    /**
     * 获取用户请求中token设置到feign发起请求中
     * @param requestTemplate
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //获取用户请求中的token设置到feign发起请求中
        String token = httpServletRequest.getHeader("Authorization");
        requestTemplate.header("Authorization",token);
    }
}
